﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MutiCodecO.codeclib;

namespace MutiCodecO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            for (int i = 0; i < (int)CodecGenerater.CodecIndex.CODECNUM; i++)
            {
                listBox1.Items.Add(CodecGenerater.codecName[i]);
            }
        }

        List<int> codecsSelectedList = new List<int>();

        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0 && listBox1.SelectedIndex < (int)CodecGenerater.CodecIndex.CODECNUM)
            {
                listBox2.Items.Add(CodecGenerater.codecName[listBox1.SelectedIndex]);
                codecsSelectedList.Add(listBox1.SelectedIndex);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex >= 0)
            {
                int i = listBox2.SelectedIndex;
                codecsSelectedList.RemoveAt(listBox2.SelectedIndex);
                listBox2.Items.RemoveAt(listBox2.SelectedIndex);
                if (i >= listBox2.Items.Count)
                    i = listBox2.Items.Count - 1;
                listBox2.SelectedIndex = i;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex >= 1)
            {
                object s = listBox2.Items[listBox2.SelectedIndex];
                listBox2.Items[listBox2.SelectedIndex] = listBox2.Items[listBox2.SelectedIndex - 1];
                listBox2.Items[listBox2.SelectedIndex - 1] = s;
                int d = codecsSelectedList[listBox2.SelectedIndex];
                codecsSelectedList[listBox2.SelectedIndex] = codecsSelectedList[listBox2.SelectedIndex - 1];
                codecsSelectedList[listBox2.SelectedIndex - 1] = d;
                listBox2.SelectedIndex--;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex < listBox2.Items.Count - 1)
            {
                object s = listBox2.Items[listBox2.SelectedIndex];
                listBox2.Items[listBox2.SelectedIndex] = listBox2.Items[listBox2.SelectedIndex + 1];
                listBox2.Items[listBox2.SelectedIndex + 1] = s;
                int d = codecsSelectedList[listBox2.SelectedIndex];
                codecsSelectedList[listBox2.SelectedIndex] = codecsSelectedList[listBox2.SelectedIndex + 1];
                codecsSelectedList[listBox2.SelectedIndex + 1] = d;
                listBox2.SelectedIndex++;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }

        CodecGenerater cg = new CodecGenerater();

        private void button6_Click(object sender, EventArgs e)
        {
            String prefix = textBox3.Text;
            String partion = textBox4.Text;
            if(checkBox1.Checked)
            {
                ICodec ic = new Num2Asii();
                prefix = ic.parse(prefix);
                partion = ic.parse(partion);
            }
            cg.setPrefix(prefix);
            cg.setPartion(partion);
            if (checkBox2.Checked)
                cg.makePrefixPartionEncoded();
            cg.setCodecs(codecsSelectedList.ToArray());
            textBox2.Text = cg.parse(textBox1.Text);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox2.Text;
        }
    }
}
